/*
 * Copyright 2011 Christoph Ludwig (christoph[at]chludwig.de). All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package de.chludwig.ehumanities.provenance.provider;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import javax.ws.rs.Consumes;
import javax.ws.rs.Produces;
import javax.ws.rs.ext.Provider;

import org.apache.abdera.model.Document;
import org.apache.abdera.model.Element;

import de.chludwig.ehumanities.provenance.Atom.AbderaInstanceFactory;

/**
 * Infrastructure for serializing and de-serializing both Atom feeds and Atom entries as XML.
 * <p>
 * The implementation follows closely the <a href="http://blogs.oracle.com/sandoz/entry/jersey_and_abdera_with_a">example</a>
 * in <a href="http://blogs.oracle.com/sandoz/">Paul Sandoz's blog</a> at Oracle.</p> 
 */
@Provider
@Produces("application/atom+xml")
@Consumes("application/atom+xml")
public class AbderaXMLProvider extends AbderaProviderBase {

  /*
   * (non-Javadoc)
   * 
   * @see de.chludwig.ehumanities.provenance.provider.AbderaProviderBase#read(java * .io.InputStream)
   */
  @Override
  protected Document<Element> read(InputStream entityStream) {
    return AbderaInstanceFactory.getInstance().getParser().parse(entityStream);
  }

  /*
   * (non-Javadoc)
   * 
   * @see
   * de.chludwig.ehumanities.provenance.provider.AbderaProviderBase#write(org
   * .apache.abdera.model.Document, java.io.OutputStream)
   */
  @Override
  protected void write(Document<Element> document, OutputStream entityStream) throws IOException {
    document.writeTo(entityStream);
  }

}
